<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>humarobotics-wifiblock-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     WifiBlockPort,  sensorI2CCustom)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: humarobotics-wifiblock-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * humarobotics-wifiblock.h provides an API for the HumaRobotics WiFiBlock Sensor.  This program</span>
<span class="comment"> * demonstrates how to use that API.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to HumaRobotics for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 2 April 2012</span>
<span class="comment"> * version 0.1</span>
<span class="comment"> */</span>


<span class="preprocessor">#include &quot;<a class="code" href="humarobotics-wifiblock_8h.html" title="HumaRobotics WiFiBlock driver.">drivers/humarobotics-wifiblock.h</a>&quot;</span>;

<span class="preprocessor">#define WIFIBLOCK_IP    &quot;192.168.43.100&quot;</span>
<span class="preprocessor"></span><span class="preprocessor">#define WIFIBLOCK_MASK  &quot;192.168.43.255&quot;</span>
<span class="preprocessor"></span><span class="preprocessor">#define WIFIBLOCK_GW    &quot;192.168.43.1&quot;</span>
<span class="preprocessor"></span><span class="preprocessor">#define WIFIBLOCK_SSID  &quot;AndroidAP&quot;</span>
<span class="preprocessor"></span><span class="preprocessor">#define WIFIBLOCK_KEY   &quot;&quot;</span>
<span class="preprocessor"></span>

<span class="comment">// Set to 1 if not already configured.</span>
<span class="preprocessor">#define DO_WIFI_CONFIG       0</span>
<span class="preprocessor"></span>
<span class="comment">// Set to 1 to execute test, enable only one at a time</span>
<span class="preprocessor">#define DO_TEST_HTTP_GET     1</span>
<span class="preprocessor"></span><span class="preprocessor">#define DO_TEST_HTTP_POST    0</span>
<span class="preprocessor"></span><span class="preprocessor">#define DO_TEST_TCP          0</span>
<span class="preprocessor"></span><span class="preprocessor">#define DO_TEST_UDP          0</span>
<span class="preprocessor"></span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * Dump the array contents on the NXT&#39;s screen</span>
<span class="comment"> * @param data the array that is to be displayed</span>
<span class="comment"> * @param size the amount of data that should be displayed</span>
<span class="comment"> */</span>
<span class="keywordtype">void</span> dumpRXData(<a name="a0"></a><a class="code" href="group__common.html#ga54b6c60d5d8ec411391ca920bf8dc97b">tBigByteArray</a> &amp;data, ubyte size)
{
  <span class="keywordtype">string</span> tmpBuff;
  <span class="keywordtype">int</span> bytesleft = size;
  <span class="keywordtype">int</span> datalen = 0;

  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i =  0; i &lt; ((size/18) + 1); i++)
        {
          datalen = (bytesleft &gt; 18) ? 18 : bytesleft;

          memset(tmpBuff, 0, 20);
          memcpy(tmpBuff, &amp;data[i*18], datalen);
          writeDebugStream(<span class="stringliteral">&quot;BUFFER: &quot;</span>);
          writeDebugStreamLine(tmpBuff);
    nxtDisplayTextLine(i+4, tmpBuff);
          bytesleft -= 18;
        }
}

<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * Show a fancy startup display</span>
<span class="comment"> */</span>
<span class="keywordtype">void</span> StartupDisplay()
{
  nxtDisplayCenteredBigTextLine(0, <span class="stringliteral">&quot;WiFi&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;Program to test&quot;</span>);
  nxtDisplayCenteredTextLine(4, <span class="stringliteral">&quot;Network with &quot;</span>);
  nxtDisplayCenteredTextLine(5, <span class="stringliteral">&quot;WifiBlock&quot;</span>);
  wait1Msec(2000);
  eraseDisplay();
  <span class="keywordflow">return</span>;
}

<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * Main program</span>
<span class="comment"> */</span>
task main () {
  StartupDisplay();

<span class="comment">// Setup the network configuration</span>
<span class="preprocessor">#if (DO_WIFI_CONFIG == 1)</span>
<span class="preprocessor"></span>  <a name="_a1"></a><a class="code" href="structt_network_info.html">tNetworkInfo</a> netInfo;

  <a name="a2"></a><a class="code" href="group___h_r_w_b.html#gadce6fb26dcb50c6a8048a320d6fa13ab">stringToIp</a>(WIFIBLOCK_IP, (<a name="a3"></a><a class="code" href="group__common.html#ga1c5690729eb47d01453399497a2b3029">tIPaddr</a>)netInfo.<a name="a4"></a><a class="code" href="structt_network_info.html#a3987dc1a3dbba53b106c2ed4332fc364">IP</a>);
  <a class="code" href="group___h_r_w_b.html#gadce6fb26dcb50c6a8048a320d6fa13ab">stringToIp</a>(WIFIBLOCK_GW, (<a class="code" href="group__common.html#ga1c5690729eb47d01453399497a2b3029">tIPaddr</a>)netInfo.<a name="a5"></a><a class="code" href="structt_network_info.html#aff136b7050438924899191b52a061988">gateway</a>);
  <a class="code" href="group___h_r_w_b.html#gadce6fb26dcb50c6a8048a320d6fa13ab">stringToIp</a>(WIFIBLOCK_MASK, (<a class="code" href="group__common.html#ga1c5690729eb47d01453399497a2b3029">tIPaddr</a>)netInfo.<a name="a6"></a><a class="code" href="structt_network_info.html#a6b6ec939233a56041fceaf9865d0e171">netmask</a>);
  netInfo.<a name="a7"></a><a class="code" href="structt_network_info.html#aebfb3beb0bbd0f126f1c807e44431656">wifi_type</a> = <a name="a8"></a><a class="code" href="group___h_r_w_b.html#ga06dbc7ecfc86d60b7690f002d6e2ed33">HRWB_SECURITY_OPEN</a>;
  netInfo.<a name="a9"></a><a class="code" href="structt_network_info.html#a3f000c56bd8458cbf6b9cc3c76685a2c">wifi_ssid</a> =  WIFIBLOCK_SSID;
  netInfo.<a name="a10"></a><a class="code" href="structt_network_info.html#adbc92e636f928aee80429e36e717a3c5">wifi_pass</a> = WIFIBLOCK_KEY;

  <a name="a11"></a><a class="code" href="group___h_r_w_b.html#ga5eccf46af5670923b91097a1b84db016">HRWBconfigNetwork</a>(WifiBlockPort, netInfo);
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="preprocessor">#if (DO_TEST_HTTP_GET == 1)</span>
<span class="preprocessor"></span>  <span class="keywordtype">string</span> tmpURL;
  <a name="_a12"></a><a class="code" href="structt_get_request.html">tGetRequest</a> getrequest;

  <a class="code" href="group___h_r_w_b.html#gadce6fb26dcb50c6a8048a320d6fa13ab">stringToIp</a>(<span class="stringliteral">&quot;192.168.43.68&quot;</span>, (<a class="code" href="group__common.html#ga1c5690729eb47d01453399497a2b3029">tIPaddr</a>)getrequest.<a name="a13"></a><a class="code" href="structt_get_request.html#a3987dc1a3dbba53b106c2ed4332fc364">IP</a>[0]);
  getrequest.<a name="a14"></a><a class="code" href="structt_get_request.html#a63c89c04d1feae07ca35558055155ffb">port</a> = 80;
  tmpURL = <span class="stringliteral">&quot;/wifiblock.html&quot;</span>;
  memcpy(getrequest.<a name="a15"></a><a class="code" href="structt_get_request.html#ad0b5abf5bb825ab2dc948b6c115d85bc">URL</a>[0], tmpURL, strlen(tmpURL) + 1);

  <a name="a16"></a><a class="code" href="group___h_r_w_b.html#ga6c0c2adf4af3e1dbde6f807745cbe82f">HRWBdoGET</a>(WifiBlockPort, getrequest);

  dumpRXData(getrequest.<a name="a17"></a><a class="code" href="structt_get_request.html#a7dd77a48b3fc5e229f5f9db5bee8ca60">RXData</a>, getrequest.<a name="a18"></a><a class="code" href="structt_get_request.html#a751d3070e77ef824ec375a233d8cde1a">RXDataLen</a>);

<span class="preprocessor">#elif (DO_TEST_HTTP_POST == 1)</span>
<span class="preprocessor"></span>  <a name="_a19"></a><a class="code" href="structt_post_request.html">tPostRequest</a> postrequest ;
  <span class="keywordtype">string</span> tmpString;

  <a class="code" href="group___h_r_w_b.html#gadce6fb26dcb50c6a8048a320d6fa13ab">stringToIp</a>(<span class="stringliteral">&quot;192.168.43.68&quot;</span>, (<a class="code" href="group__common.html#ga1c5690729eb47d01453399497a2b3029">tIPaddr</a>)postrequest.<a name="a20"></a><a class="code" href="structt_post_request.html#a3987dc1a3dbba53b106c2ed4332fc364">IP</a>);
  postrequest.<a name="a21"></a><a class="code" href="structt_post_request.html#a63c89c04d1feae07ca35558055155ffb">port</a> = 80;
  tmpString = <span class="stringliteral">&quot;msg=hello&quot;</span>;
  memcpy(postrequest.<a name="a22"></a><a class="code" href="structt_post_request.html#a6c093ddf7de5f28ffed73071e70b1232">TXData</a>, tmpString, strlen(tmpString) + 1);
  postrequest.<a name="a23"></a><a class="code" href="structt_post_request.html#aa300ad171e0161e703a3d0c770ef09e1">TXDataLen</a> = strlen(tmpString) + 1;

  tmpString = <span class="stringliteral">&quot;/post.php&quot;</span>;
  memcpy(postrequest.<a name="a24"></a><a class="code" href="structt_post_request.html#ad0b5abf5bb825ab2dc948b6c115d85bc">URL</a>, tmpString, strlen(tmpString) + 1);

  <a name="a25"></a><a class="code" href="group___h_r_w_b.html#gad324d3b8893e2ac825d38bc635c77b59">HRWBdoPOST</a>(WifiBlockPort, postrequest);

<span class="preprocessor">#elif (DO_TEST_TCP == 1)</span>
<span class="preprocessor"></span>  <a name="_a26"></a><a class="code" href="structt_t_c_p_request.html">tTCPRequest</a> tcprequest;

  <a class="code" href="group___h_r_w_b.html#gadce6fb26dcb50c6a8048a320d6fa13ab">stringToIp</a>(<span class="stringliteral">&quot;192.168.43.68&quot;</span>, (<a class="code" href="group__common.html#ga1c5690729eb47d01453399497a2b3029">tIPaddr</a>)tcprequest.<a name="a27"></a><a class="code" href="structt_t_c_p_request.html#a3987dc1a3dbba53b106c2ed4332fc364">IP</a>);
  tcprequest.<a name="a28"></a><a class="code" href="structt_t_c_p_request.html#a63c89c04d1feae07ca35558055155ffb">port</a> = 8080;
  tmpString = <span class="stringliteral">&quot;Hi from WiFiBlock\n&quot;</span>;
  memcpy(tcprequest.<a name="a29"></a><a class="code" href="structt_t_c_p_request.html#afcc9ba355c6dbfbacf29c100c594c22d">TXData</a>, tmpString, strlen(tmpString) + 1);
  tcprequest.<a name="a30"></a><a class="code" href="structt_t_c_p_request.html#aa300ad171e0161e703a3d0c770ef09e1">TXDataLen</a> = strlen(tmpString) + 1;

  <a name="a31"></a><a class="code" href="group___h_r_w_b.html#ga5a73cc99dfb1aea10520a7154ca7baf9">HRWBdoTCP</a>(WifiBlockPort, tcprequest);

  dumpRXData(tcprequest.<a name="a32"></a><a class="code" href="structt_t_c_p_request.html#acec89450ce66e3641999cc2f7e7e338c">RXData</a>, tcprequest.<a name="a33"></a><a class="code" href="structt_t_c_p_request.html#a751d3070e77ef824ec375a233d8cde1a">RXDataLen</a>);

<span class="preprocessor">#elif (DO_TEST_UDP == 1)</span>
<span class="preprocessor"></span>  <a name="_a34"></a><a class="code" href="structt_u_d_p_request.html">tUDPRequest</a> udprequest;

  <a class="code" href="group___h_r_w_b.html#gadce6fb26dcb50c6a8048a320d6fa13ab">stringToIp</a>(<span class="stringliteral">&quot;192.168.43.68&quot;</span>, (<a class="code" href="group__common.html#ga1c5690729eb47d01453399497a2b3029">tIPaddr</a>)udprequest.<a name="a35"></a><a class="code" href="structt_u_d_p_request.html#a3987dc1a3dbba53b106c2ed4332fc364">IP</a>);
  udprequest.<a name="a36"></a><a class="code" href="structt_u_d_p_request.html#a32be3c23ead7f4709d3cece7cfe06d4e">dport</a> = 8080;
  udprequest.<a name="a37"></a><a class="code" href="structt_u_d_p_request.html#a32c63c3542a21dfdb3ed1164140c254f">sport</a> = 5000;
  tmpString = <span class="stringliteral">&quot;Hi from WiFiBlock\n&quot;</span>;
  memcpy(udprequest.<a name="a38"></a><a class="code" href="structt_u_d_p_request.html#afcc9ba355c6dbfbacf29c100c594c22d">TXData</a>, tmpString, strlen(tmpString) + 1);
  udprequest.<a name="a39"></a><a class="code" href="structt_u_d_p_request.html#aa300ad171e0161e703a3d0c770ef09e1">TXDataLen</a> = strlen(tmpString) + 1;

  <a name="a40"></a><a class="code" href="group___h_r_w_b.html#ga5181928fedfc13ff551e59f19ced6e91">HRWBdoUDP</a>(WifiBlockPort, udprequest);

  dumpRXData(udprequest.<a name="a41"></a><a class="code" href="structt_u_d_p_request.html#acec89450ce66e3641999cc2f7e7e338c">RXData</a>, udprequest.<a name="a42"></a><a class="code" href="structt_u_d_p_request.html#a751d3070e77ef824ec375a233d8cde1a">RXDataLen</a>);

<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
  PlaySound(soundBeepBeep);
  <span class="keywordflow">while</span>(<span class="keyword">true</span>) EndTimeSlice();
}

<span class="comment">/*</span>
<span class="comment"> * $Id: humarobotics-wifiblock-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
